<template>
  <!-- 选择实验室模板 -->
  <el-drawer title="实验室检查模板：" size="600px" :visible="value" custom-class="drawer-box" :wrapperClosable="false" :destroy-on-close="true" @open="onOpen" @close="onClose" :append-to-body="true">
    <div v-loading="loading">
      <div class="p-sm" style="padding-bottom:0;">
        <el-form :inline="true" @submit.native.prevent="getTemplate(-1)">
          <el-form-item>
            <el-input v-model="form.name" placeholder="模板名称" clearable ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" circle icon="el-icon-search" native-type="submit"> </el-button>
          </el-form-item>
        </el-form>
      </div>
      <table class="table-box">
        <thead>
          <tr>
            <th>模板名称</th>
            <th>项目</th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(item,index) in tableList" :key="index" @click="onClickItem(item)">
            <td style="min-width:150px;">{{item.template.name}}</td>
            <td>
              <span v-for="(item,index) in item.baseTemplateAdviceBeans" :key="index">{{index>0?"，":''}}{{item.adviceDesc}}</span>
            </td>
          </tr>
        </tbody>
      </table>
      <div v-if="tableList.length == 0" style="color:#999;padding:10px 0;text-align:center;">
        <i class="iconfont iconwushuju" style="font-size:40px;"></i>
        <div>暂无数据</div>
      </div>
      <br>
      <pager v-model="pager" @change-pagenum="getTemplate"></pager>
    </div>
  </el-drawer>
</template>
<script>
export default {
  props: ["value"],
  components: {},
  data() {
    return {
      tableList: [],
      loading:false,
      pager: { pageSize: 20, pageNum: 1, total: 0 },
      form: {
        name: "",
        status:1
      }
    };
  },
  methods: {
    onClickItem(obj) {
      let th = this;
      th.$emit("change", obj);
      th.onClose();
    },
    getTemplate(type) {
      let th = this;
      if (type == -1) {
        th.pager.pageNum = 1;
        th.pager.total = 0;
      }
      let j = {};
      Object.assign(j, th.pager, th.form);
      th.tableList = [];
      th.loading=true;
      th.$api.getLaboratoryInspectionTemplatePageList(j).then(res => {
        if (res.executed) {
          if (res.dataBody.list) th.tableList = res.dataBody.list;
          th.pager.total = res.dataBody.total;
        }
        th.loading=false;
      });
    },
    onOpen() {
      let th = this;
      th.$nextTick(function() {
        th.getTemplate(-1);
      });
    },
    onClose() {
      let th = this;
      th.$emit("input", false);
    }
  }
};
</script>
